package com.njym.java.security.admin.rest;


import com.github.pagehelper.PageInfo;
import com.njym.java.security.admin.biz.CludCodeBiz;
import com.njym.java.security.admin.entity.CludCode;

import com.njym.java.security.admin.entity.User;

import com.njym.java.security.common.msg.ObjectRestResponse;

import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("cludCode")
public class CludCodeController extends BaseController<CludCodeBiz,CludCode> {
    @RequestMapping(value = "/queryclubs",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<User> queryClubs(){
        return new ObjectRestResponse<User>().rel(true).data(baseBiz.queryClub());
    }

    @RequestMapping(value = "/lists",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<CludCode> list(String code, Integer clubId,
        String useFlag, Integer useId,
        @RequestParam(value = "page", defaultValue = "1") Integer page,
        @RequestParam(value = "limit", defaultValue = "10") Integer limit){
        List<CludCode> list = baseBiz.querySelective(code, clubId, useFlag, useId, page, limit);
        int total = baseBiz.countSelective(code, clubId, useFlag, useId);
        Map<String, Object> data = new HashMap<>(2);
        data.put("list", list);
        data.put("total", total);
        return new ObjectRestResponse<User>().rel(true).data(data);
    }

    @RequestMapping(value = "/inserts",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<CludCode> inserts(Integer num, Integer cludId){
        CludCode cludCode = new CludCode();
        cludCode.setCludId(cludId);
        cludCode.setCreatTime(new Date());
        cludCode.setUseFlag("0");
        for(int i = 0; i < num; i++){
            baseBiz.insertUUID(cludCode);
        }
        return new ObjectRestResponse<User>().rel(true).data(ResponseUtil.ok());
    }
}